#pragma once

#include <stdio.h>
#include<unistd.h>
#include "process.h"
#include<time.h>


const int base = 20;
double total = 2048.0;
double once = 0.1;

//一个刷新的函数指针类型
typedef void(*flush_t)(double total,double current);

void DownLoad(flush_t f)
{
    double current = 0.0;
    while(current < total)
    {
        //模拟下载行为
        int r = rand()%base+1;
        double speed = r*once;
        current += speed;

        if(current > total) current = total;
        
        usleep(1000);
        
        //根据真实形态动态刷新
        f(total,current);
    }

    printf("\n");
    
}

int main()
{
    DownLoad(Process);
    return 0;
}
